package com.stlm2.controller;

import com.stlm2.dems.user.entity.Account;
import com.stlm2.dems.entity.User;
import com.stlm2.dems.user.service.AccountService;
import com.stlm2.dems.service.UserService;
import com.stlm2.util.codecontent.CodeContent;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * Created by apple on 2017/5/24.
 */

@Controller
@RequestMapping("/accountC")
public class AccountController {
    @Resource
    private AccountService accountService;

    @Resource
    private UserService userService;

    @ResponseBody
    @RequestMapping(value="/getAccount.json",produces="application/json;charset=UTF-8")
    public String getAccount(String companyCode,String token, ModelMap model){
        if (StringUtils.isEmpty(token)) {
            //token 为空 请登录 访问
            return CodeContent.getModelByCode(-1,"", model);
        }
        User user= userService.getByToken(token);
        if(user==null){
            //缓存中没有取出 用户对象  请登陆 再访问
            return CodeContent.getModelByCode(-1,"", model);
        }
        Account account=accountService.getByUserId(user.getId());
        if(account!=null) {
            model.put("account", accountService.buildModel(account));
        }
        return CodeContent.getModelByCode(1,"",model);
    }

    /*
    *账户概况
    *ffl
    *2017-06-14 14:12:06
     */
    @ResponseBody
    @RequestMapping(value="/getAccountSurvey.json",produces="application/json;charset=UTF-8")
    public  String accountStatement(String companyCode,String token){
        String date="";

            date=accountService.accountStatment(token);

        return  date;
    }

}
